﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    /// <summary>
    /// 发货单与运输单号关系
    /// </summary>
    public partial class TVV20
    {

        public TVV20()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VVVAVIS();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void vwMaster_CurrentChanged(object sender, System.EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            /*
            SART = ((VVVAVIS)MV).VVAVERSART;
            VSPED = ((VVVAVIS)MV).VVASPED;*/
            
            
        }
        public override void NewCommand(object sender, RoutedEventArgs e)
        {
            dwData = TBMain.NewRow();
            if (AVISNR.Length < 8)
                return;
            if (LIEFSCH.Length < 8)
                return;
            dwData["VVAMANDANT"] = app.Mandant;
            dwData["VVAAVISNR"] = AVISNR;
            dwData["VVAFILLER"] = LIEFSCH;
            ((VVVAVIS)MV).UpdateVVAVIS(dwData, 5);//更新发货单
            ORDERNUM = "";
            ORDERNUM = AVISNR;
            base.NewCommand(sender, e);
        }
        public override void DeleteCommand(object sender, RoutedEventArgs e)
        { 
            if (LIEFSCH.Length < 8)
                return;
            dwData = TBMain.NewRow(); 
            dwData["VVAMANDANT"] = app.Mandant;
            dwData["VVAAVISNR"] = "00000000";
            dwData["VVAFILLER"] = LIEFSCH;
            ((VVVAVIS)MV).UpdateVVAVIS(dwData, 5);//更新发货单
            base.DeleteCommand(sender, e);
        }
        public override void LOADBYAUF()
        {
            TBMain.Clear();
            if (ORDERNUM.Length < 8)
                return;
            if (ORDERNUM.Trim() == "00000000") return;
            dwData = TBMain.NewRow();
            dwData["VVAMANDANT"] = app.Mandant;
            dwData["VVAAVISNR"] = ORDERNUM;
            SResult = ((VVVAVIS)MV).QueryVVAVIS(dwData, 2); 
            MergeData(SResult, true);
        }

        public override void OnAVISNRChg(string value)
        {
            ORDERNUM = "";
            ORDERNUM = value;
            if (AVISNR.Length < 8)
                return;
            if (LIEFSCH.Length < 8)
                return;
            dwData = TBMain.NewRow();
            dwData["VVAMANDANT"] = app.Mandant;
            dwData["VVAAVISNR"] = AVISNR;
            dwData["VVAFILLER"] = LIEFSCH;
            ((VVVAVIS)MV).UpdateVVAVIS(dwData, 5);//更新发货单
            
            base.OnAVISNRChg(value);
        }
        public override void OnSARTChg(string value)
        { 
            SHIPWAY = value.PadRight(3) + VSPED.PadRight(3) + " ";
            base.OnSARTChg(value);
        }
        public override void OnVSPEDChg(string value)
        {
            SHIPWAY = SART.PadRight(3) + value.PadRight(3) + " ";
            base.OnVSPEDChg(value);
        }
    }
}